﻿using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;


namespace Kernelx.Contexts.Repositories
{
    using Core;
    using System;

    internal class ModelStore<T> : IModelStore<T> where T : class, new()
    { 
        private readonly DbSet<T> _store;
        public ModelStore(DbSet<T> dbSet) => _store = dbSet;

        #region 改动操作

        public void Insert(T ety) => _store.Add(ety);

        public void Insert(IList<T> etys) => _store.AddRange(etys);

        public void PhysicsDelete(T ety) => _store.Remove(ety);
        public void PhysicsDelete(IList<T> etys) => _store.RemoveRange(etys);


        public IModelTrack<T> Update(T ety) => new ModelTrack<T>(_store.Update(ety));

        #endregion
         
        public T Find(params object[] ids)=> _store.Find(ids);

        public IQueryable<T> GetQuery(bool isTracking = false)
            => isTracking ? _store : _store.AsNoTracking();
         
    }
}
